package com.loong.game2048.config;

import com.loong.game2048.interceptor.AuthorizationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author lyx
 * @date 2020/5/9 16:44
 */
@Configuration
//@EnableWebMvc  会取消掉springboot对静态文件的默认配置
public class InterceptorConfig implements WebMvcConfigurer {

    //构建bean对象，不如会出现一些对象无法初始化的情况，如userserver
    @Bean
    public HandlerInterceptor getMyInterceptor(){
        return new AuthorizationInterceptor();
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getMyInterceptor());
    }
}
